package it.sarasini.dmp;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MusicOpenHelper extends SQLiteOpenHelper {
	
	/*
	 * To create and upgrade a database in your Android application you usually 
	 * subclass "SQLightOpenHelper". In this class you need to override the methods 
	 * onCreate() to create the database and onUpgrade() to upgrade the database in 
	 * case of changes in the database schema. Both methods receive an 
	 * "SQLightDatabase" object.
	 * SQLightOpenHelper provides the methods getReadableDatabase() and 
	 * getWriteableDatabase() to get access to an "SQLightDatabase" object which 
	 * allows database access either in read or write mode. 
	 * For the primary key of the database you should always use the identifier 
	 * "_id" as some of Android functions rely on this standard.
	 */
	
	public static final int DATABASE_VERSION = 1;
	public static final String DATABASE_NAME = "music.db";
	
    public static final String ARTIST_TABLE_NAME = "artist";
    public static final String FILE_TABLE_NAME = "file";
    
    private static final String Q_ARTIST_TABLE_CREATE =
    	"CREATE TABLE " + ARTIST_TABLE_NAME + " (	_id INTEGER PRIMARY KEY AUTOINCREMENT , " +
    												"name TEXT);";
    private static final String Q_FILE_TABLE_CREATE =
    	"CREATE TABLE " + FILE_TABLE_NAME + " ( 	_id INTEGER PRIMARY KEY AUTOINCREMENT , " +
    												"path TEXT , " +
    												"artist_id INTEGER, " +
    												"title TEXT , " +
    												"lenght_ms INTEGER);";
    	

    public MusicOpenHelper(Context context) {
    	
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
    	
        db.execSQL(Q_ARTIST_TABLE_CREATE);
        db.execSQL(Q_FILE_TABLE_CREATE);
    }

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { }
	
}
